//
//  collectionViewController.m
//  TripGo
//
//  Created by mingyang on 15-7-21.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "collectionViewController.h"
#import "Database.h"
#import "CollectionTableViewCell.h"
#import "TravelPushViewController.h"
#import "SpecialDetailViewController.h"
@interface collectionViewController () <UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) NSMutableArray *arrayData;
@end

@implementation collectionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"我的收藏";
    self.arrayData = [NSMutableArray array];
    [self createView];
}
- (void)createView
{
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    [_tableView release];
}
- (void)viewDidAppear:(BOOL)animated
{
    NSMutableArray *array = [NSMutableArray arrayWithArray:[Database selectData]];
    self.arrayData = array;
    [self.tableView reloadData];
    if(self.arrayData.count == 0) {
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 80)];
        label.text = @"暂无收藏！";
        [self.view addSubview:label];
        label.font = [UIFont systemFontOfSize:23];
        label.font = [UIFont boldSystemFontOfSize:25];
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = [UIColor grayColor];
        label.center = CGPointMake(self.view.center.x, self.view.center.y - 64);
    }
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.arrayData.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"cell";
    CollectionTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[[CollectionTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease];
    }
    //cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    DbModel *model = [self.arrayData objectAtIndex:indexPath.row];
    [cell setDbModel:model];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    DbModel *model = [self.arrayData objectAtIndex:indexPath.row];
    if (model.choose == 0) {
        TravelPushViewController *travel = [[TravelPushViewController alloc] init];
        travel.number = model.titleId;
        [self.navigationController pushViewController:travel animated:YES];
        [travel release];
    } else if (model.choose == 1) {
        SpecialDetailViewController *subject = [[SpecialDetailViewController alloc] init];
        subject.number = model.titleId;
        [self.navigationController pushViewController:subject animated:YES];
    } else if (model.choose == 2) {
//        JourneyViewController *journey = [[JourneyViewController alloc] init];
//        journey.number = model.titleId;
//        journey.isStrategy = 1;
//        [self.navigationController pushViewController:journey animated:YES];
//        [journey release];
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
